package com.cdshangpai.utils.offlinecache.hotal;

import android.util.Log;

import com.cdshangpai.photoapp.LogConfig;
import com.cdshangpai.utils.api.Api;
import com.cdshangpai.utils.db.beans.Case;
import com.cdshangpai.utils.db.beans.Hotal;
import com.cdshangpai.utils.log.LogUtil;
import com.cdshangpai.utils.offlinecache.DbVersion;
import com.cdshangpai.utils.offlinecache.base.BaseCacheProcessor;
import com.cdshangpai.utils.offlinecache.base.DataDownloader;
import com.cdshangpai.utils.offlinecache.base.query.HotalQuery;

import java.util.List;

/**
 * 酒店数据缓存处理器
 */
public class HotalCacheProcessor {
    Api api;
    private HotalQuery hotalQuery;

    public HotalCacheProcessor()
    {
        api=new Api();
        hotalQuery=new HotalQuery();
    }

    /**
     * 删除，增加，修改酒店数据，并下载数据包含的图片
     * @param serverHotalVersions
     * @return
     */
    public boolean begin(List<DbVersion> serverHotalVersions)
    {
        DataDownloader dataDownloader=new DataDownloader() {
            @Override
            public List download(List ids) {
                return api.queryHotal(ids);
            }
        };
        List<Hotal> localDatas=hotalQuery.query();
        LogUtil.save("开始同步酒店...");
        Log.i(LogConfig.logTag,"开始同步酒店...");
        return new BaseCacheProcessor<Case>()
                .setDbQuery(hotalQuery)
                .setDataDownloader(dataDownloader)
                .setLocalDatas(localDatas)
                .setServerVersion(serverHotalVersions)
                .forHotal()
                .begin();
    }
}
